// pages/thirdPublish/thirdPublish.js

//const homeData = require('../../antiqueData/antiqueData.js'); 
var app = getApp();
var util = require('../../utils/util.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
      
  },

  /** 
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var userId = options.userid;
    var thirdDataUrl = app.globalData.antiqueBaseUrl + "queryTopicByOpenId.html";
    util.httpMine(thirdDataUrl, userId, this.initData);
  },

  onAntiqueTap: function(event){
    var antiqueId = event.currentTarget.dataset.antiqueid;
    wx.navigateTo({
      url: "../detail/detail?id=" + antiqueId 
    })
  },  

  initData: function(allData){
    var that = this;
    var homeAntique = [];
    var showThreeImg = [];
    allData.forEach((antique)=>{
      var subject = antique.imgs.slice(0,3)
      var threeImg = [];
      for (var i in subject){
        var item1 = subject[i];
        var item2 = app.globalData.antiqueImgUrl + item1;
        threeImg.push(item2);
      }
      var temp = {
        antiqueId: antique.id,
        avatar: antique.user.headImg,
        nickName: antique.user.name,
        publishTime: antique.times,
        antiqueName: antique.type.name,
        antiqueDesc: antique.content,
        browserNum: antique.views,
        showImg: threeImg
      }
      homeAntique.push(temp);
    })
    homeAntique.forEach((idx)=>{
      var avatar = idx.avatar;
      var nickName = idx.nickName;
      that.setData({
        avatar: avatar,
        nickName: nickName  
      })
    })  
    this.setData({
      taData: homeAntique,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})